package ext.tianma.cascade.datautility;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.dataUtilities.DefaultDataUtility;
import com.ptc.core.components.rendering.guicomponents.AttributeInputCompositeComponent;
import com.ptc.core.components.rendering.guicomponents.ComboBox;
import ext.tianma.bom.service.sourcingInterface.SourcingForPLMService;
import org.apache.log4j.Logger;
import wt.fc.WTObject;
import wt.log4j.LogR;
import wt.util.WTException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class PartBrandNameDataUtility extends DefaultDataUtility {


    private static final Logger log;
    private static HashMap<String, HashMap<String, List<String>>> CACHE;

    static {
        try {
            log = LogR.getLogger(PartBrandNameDataUtility.class.getName());
        } catch (Exception exception) {
            throw new ExceptionInInitializerError(exception);
        }
    }

    /**
     *
     * @param columnName
     * @param object
     * @param context
     * @return
     * @throws WTException
     */
    @Override
    public Object getDataValue(String columnName, Object object, ModelContext context) throws WTException {

        System.out.println("品牌名称-columnName:" + columnName);
        AttributeInputCompositeComponent component = (AttributeInputCompositeComponent) getDataValueInternal(
                columnName, object, context, false);

        ArrayList<String> options = new ArrayList<>();
        options.add("");

        ComboBox cb = new ComboBox();

        cb.setLabel(component.getLabel());
        System.out.println("component.getLabel():" + component.getLabel());

        cb.setName(component.getName());
        System.out.println("component.getName():" + component.getName());

        cb.setId(component.getId());

        System.out.println("component.getId():" + component.getId());

        cb.setColumnName(component.getColumnName());
        System.out.println("component.getColumnName():" + component.getColumnName());

        cb.setMultiSelect(false);
        cb.setInternalValues(options);
        cb.setValues(options);

        ArrayList<String> brandNames = (ArrayList<String>) SourcingForPLMService.queryAllBrandNameByState("淘汰");
        System.out.println("11111111brandNames======>>" + brandNames + "size:" + brandNames.size());

        if ("brandName".equals(columnName)) {
            options.addAll(brandNames);
            cb.addJsAction("onchange", "changeBrandName(this)");
        }

        return cb;
    }


    /**
     * 获取品牌名称
     *
     * @param value
     * @param obj
     * @return
     * @throws WTException
     */
    private ComboBox getBrandNameComponent(String value, WTObject obj) throws WTException {

        ArrayList<String> brandNames = (ArrayList<String>) SourcingForPLMService.queryAllBrandNameByState("淘汰");

        System.out.println("11111111brandNames======>>" + brandNames + "size:" + brandNames.size());

        ComboBox combobox = new ComboBox(brandNames, brandNames, null);

        return combobox;
    }


}
